//
//  RequestApi+Common.m
//  MexicoLoan
//
//  Created by WXP on 2025/2/28.
//

#import "RequestApi+Common.h"

@implementation RequestApi (Common)

#pragma mark - 风控埋点
+ (void)requestAddRiskControlTrackingWithType:(NSString *)type
                                    startTime:(NSString *)startTime
                                      endTime:(NSString *)endTime
                             delegate:(id <RequestDelegate> _Nullable)delegate
                            success:(void (^)(NSDictionary * response, id mark))success
                            failure:(void (^)(NSString * errorStr, id mark))failure{
    [[LocationService sharedInstance] startUpdatingLocation];
    CLLocationCoordinate2D currentLocation = [[LocationService sharedInstance] getCurrentLocation];
    NSString * lat = currentLocation.latitude  == 0 ? @"" : [NSString stringWithFormat:@"%f", currentLocation.latitude];
    NSString * lon = currentLocation.longitude == 0 ? @"" : [NSString stringWithFormat:@"%f", currentLocation.longitude];
    NSString * adid = [GlobalMethod getAdid];
    NSDictionary * dic = @{
        KEY_adid: readStr(adid),
        KEY_sceneType: type,
        KEY_deviceNo: [GlobalMethod getDeviceNo],
        KEY_userRandomKey: [GlobalMethod getUserRandomKey],
        KEY_latitude: readStr(lat),
        KEY_longitude: readStr(lon),
        KEY_startTime: readStr(startTime),
        KEY_endTime: readStr(endTime)
    };
    [RequestApi postUrl:[NSString stringWithFormat:@"%@%@/%@",URL_HEAD, COMMON_ADD_RISK_CONTROL_TRACKING_NEW,type] delegate:delegate parameters:dic success:success failure:failure];
}

#pragma mark - 检查是否上传扩展信息
+ (void)requestCheckUploadDeviceInfoWithDelegate:(id <RequestDelegate>)delegate
                            success:(void (^)(NSDictionary * response, id mark))success
                                         failure:(void (^)(NSString * errorStr, id mark))failure{
    [RequestApi postUrl:[NSString stringWithFormat:@"%@%@",URL_HEAD, AUTH_CHECK_UPLOAD_DEVICE_INFO] delegate:delegate parameters:nil success:success failure:failure];
}

#pragma mark - 上传拓展数据
+ (void)requestUploadExtInfoWithExtInfo:(NSDictionary *)extInfo
                     delegate:(id <RequestDelegate> _Nullable)delegate
                            success:(void (^)(NSDictionary * response, id mark))success
                            failure:(void (^)(NSString * errorStr, id mark))failure{
    
    NSDictionary * dic = @{
        KEY_extInfoReq: extInfo,
    };
    [RequestApi postUrl:[NSString stringWithFormat:@"%@%@",URL_HEAD, AUTH_UPLOAD_EXTINFO] delegate:delegate parameters:dic success:success failure:failure];
}

#pragma mark - 字典列表
+ (void)requestCommonDictListWithType:(NSString *)type
                             delegate:(id <RequestDelegate> _Nullable)delegate
                            success:(void (^)(NSDictionary * response, id mark))success
                            failure:(void (^)(NSString * errorStr, id mark))failure{
    [RequestApi postUrl:[NSString stringWithFormat:@"%@%@/%@",URL_HEAD, COMMON_DICTLIST_NEW, type] delegate:delegate parameters:nil success:success failure:failure];
}

#pragma mark - 银行列表
+ (void)requestBankListWithDelegate:(id <RequestDelegate> _Nullable)delegate
                            success:(void (^)(NSDictionary * response, id mark))success
                            failure:(void (^)(NSString * errorStr, id mark))failure{
    [RequestApi postUrl:[NSString stringWithFormat:@"%@%@",URL_HEAD, COMMON_BANK_LIST] delegate:delegate parameters:nil success:success failure:failure];
}

#pragma mark - 用户提交评分
+ (void)requestSubmitRatingWithScore:(NSInteger)score
                             suggest:(NSString *)suggest
                  isFromFalseProduct:(NSInteger)isFromFalseProduct
                                        delegate:(id <RequestDelegate>)delegate
                            success:(void (^)(NSDictionary * response, id mark))success
                            failure:(void (^)(NSString * errorStr, id mark))failure{
    NSDictionary * dic = @{
        KEY_score: @(score),
        KEY_suggest: readStr(suggest)
    };
    if (isFromFalseProduct>0){
        dic = @{
            KEY_score:   @(score),
            KEY_suggest: readStr(suggest),
            KEY_isFromFalseProduct: @(isFromFalseProduct),
        };
    }
    [RequestApi postUrl:[NSString stringWithFormat:@"%@%@",URL_HEAD,USER_SUBMIT_RATING] delegate:delegate parameters:dic success:success failure:failure];
}

#pragma mark - 获取客服信息
+ (void)requestCustomerServiceInfoWithDelegate:(id <RequestDelegate> _Nullable)delegate
                            success:(void (^)(NSDictionary * response, id mark))success
                            failure:(void (^)(NSString * errorStr, id mark))failure{
    [RequestApi postUrl:[NSString stringWithFormat:@"%@%@",URL_HEAD,COMMON_CUSTOMER_SERVICE_INFO] delegate:delegate parameters:nil success:success failure:failure];
}

#pragma mark - app公告
+ (void)requestAppNoticeWithDelegate:(id <RequestDelegate> _Nullable)delegate
                            success:(void (^)(NSDictionary * response, id mark))success
                            failure:(void (^)(NSString * errorStr, id mark))failure{
    [RequestApi postUrl:[NSString stringWithFormat:@"%@%@",URL_HEAD, COMMON_APP_NOTICE] delegate:delegate parameters:nil success:success failure:failure];
}

#pragma mark - app更新配置
+ (void)requestAppUpdateConfigWithDelegate:(id <RequestDelegate> _Nullable)delegate
                            success:(void (^)(NSDictionary * response, id mark))success
                            failure:(void (^)(NSString * errorStr, id mark))failure{
    [RequestApi postUrl:[NSString stringWithFormat:@"%@%@",URL_HEAD, COMMON_APPUPDATECONFIG] delegate:delegate parameters:nil success:success failure:failure];
}

#pragma mark - 获取App的banner图片
+ (void)requestAppBannerUrlWithPage:(NSInteger)page
                           delegate:(id <RequestDelegate> _Nullable)delegate
                            success:(void (^)(NSDictionary * response, id mark))success
                            failure:(void (^)(NSString * errorStr, id mark))failure{
    [RequestApi postUrl:[NSString stringWithFormat:@"%@%@%ld",URL_HEAD, INDEX_BANNER_URL, page] delegate:delegate parameters:nil success:success failure:failure];
}

#pragma mark - 是否展示提额弹窗
+ (void)requestIncreaseCreditPopWithDelegate:(id <RequestDelegate> _Nullable)delegate
                            success:(void (^)(NSDictionary * response, id mark))success
                            failure:(void (^)(NSString * errorStr, id mark))failure{
    [RequestApi postUrl:[NSString stringWithFormat:@"%@%@",URL_HEAD, COMMON_INCREASECREDIT_POP] delegate:delegate parameters:nil success:success failure:failure];
}

#pragma mark - 打点
+ (void)requestHitPointWithPageName:(NSString *)pageName
                             action:(NSString *)action
                            extInfo:(NSString *)extInfo
                           delegate:(id <RequestDelegate> _Nullable)delegate
                            success:(void (^)(NSDictionary * response, id mark))success
                            failure:(void (^)(NSString * errorStr, id mark))failure{
    NSDictionary * dic = @{
        KEY_adid: [GlobalMethod getAdid],
        KEY_userRandomKey: [GlobalMethod getUserRandomKey]
    };
    if(isStr(extInfo)){
        dic = @{
            KEY_extInfo: readStr(extInfo),
            KEY_adid: [GlobalMethod getAdid],
            KEY_userRandomKey: [GlobalMethod getUserRandomKey]
        };
    }
    [RequestApi postUrl:[NSString stringWithFormat:@"%@%@/%@/%@",URL_HEAD, COMMON_USER_BEHAVIOR_RECORD, pageName, action] delegate:delegate parameters:dic success:success failure:failure];
}

#pragma mark - 用户详情行为埋点
+ (void)requestBuryPointWithPageName:(NSString *)pageName
                         featureName:(NSString *)featureName
                                type:(NSString *)type
                              action:(NSString *)action
                            delegate:(id <RequestDelegate> _Nullable)delegate
                             success:(void (^)(NSDictionary * response, id mark))success
                             failure:(void (^)(NSString * errorStr, id mark))failure{
    NSDictionary * dic = @{
        KEY_deviceNo: [GlobalMethod getDeviceNo]
    };
    [RequestApi postUrl:[NSString stringWithFormat:@"%@%@%@/%@/%@/%@", URL_HEAD, COMMON_USER_BEHAVIOR_TRACK, pageName, featureName, type, action] delegate:delegate parameters:dic success:success failure:failure];
}

@end
